<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Module: ViewModels::Helpers::Mapping
  
    &mdash; Documentation by YARD 0.8.3
  
</title>

  <link rel="stylesheet" href="../../css/style.css" type="text/css" media="screen" charset="utf-8" />

  <link rel="stylesheet" href="../../css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../../';
  framesUrl = "../../frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../../_index.html">Index (M)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../../ViewModels.html" title="ViewModels (module)">ViewModels</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Helpers.html" title="ViewModels::Helpers (module)">Helpers</a></span></span>
     &raquo; 
    <span class="title">Mapping</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Module: ViewModels::Helpers::Mapping
  
  
  
</h1>

<dl class="box">
  
  
    
  
    
  
  
  
    <dt class="r1 last">Defined in:</dt>
    <dd class="r1 last">lib/view_models/helpers/collection.rb<span class="defines">,<br />
  lib/view_models/helpers/mapping.rb</span>
</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    
<p>Mapping helpers install collection_view_model_for and view_model_for, which
you can use with instances to conveniently instantiate a view model for it</p>


  </div>
</div>
<div class="tags">
  

</div><h2>Defined Under Namespace</h2>
<p class="children">
  
    
  
    
      <strong class="classes">Classes:</strong> <span class='object_link'><a href="Mapping/Collection.html" title="ViewModels::Helpers::Mapping::Collection (class)">Collection</a></span>
    
  
</p>







  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#collection_view_model_for-instance_method" title="#collection_view_model_for (instance method)">- (Object) <strong>collection_view_model_for</strong>(array_or_pagination, context = self) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Construct a view_model for a collection.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#default_view_model_class_for-instance_method" title="#default_view_model_class_for (instance method)">- (Object) <strong>default_view_model_class_for</strong>(model) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Returns the default view_model class for the given model instance.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#specific_view_model_class_for-instance_method" title="#specific_view_model_class_for (instance method)">- (Object) <strong>specific_view_model_class_for</strong>(model) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Returns a specific view_model class for the given model instance.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#view_model_class_for-instance_method" title="#view_model_class_for (instance method)">- (Object) <strong>view_model_class_for</strong>(model) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Get the view_model class for the given model instance.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#view_model_for-instance_method" title="#view_model_for (instance method)">- (Object) <strong>view_model_for</strong>(model, context = self) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Create a new view_model instance for the given model instance with the
given arguments.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="collection_view_model_for-instance_method">
  
    - (<tt>Object</tt>) <strong>collection_view_model_for</strong>(array_or_pagination, context = self) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
  <div class="note todo">
    <strong>TODO:</strong>
    <div class='inline'>
<p>Think about moving it into view_model_for, or renaming it view_models_for.</p>
</div>
  </div>


<p>Construct a view_model for a collection.</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


16
17
18</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/view_models/helpers/collection.rb', line 16</span>

<span class='kw'>def</span> <span class='id identifier rubyid_collection_view_model_for'>collection_view_model_for</span> <span class='id identifier rubyid_array_or_pagination'>array_or_pagination</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='kw'>self</span>
  <span class='const'>Collection</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_array_or_pagination'>array_or_pagination</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="default_view_model_class_for-instance_method">
  
    - (<tt>Object</tt>) <strong>default_view_model_class_for</strong>(model) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Returns the default view_model class for the given model instance.</p>

<p>Default class name is: ViewModels::&lt;ModelClassName&gt;</p>

<p>Override this method if you'd like to change the <em>default</em>
model-to-view_model class mapping.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt>NameError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>if a corresponding ViewModels constant cannot be loaded.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


42
43
44</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/view_models/helpers/mapping.rb', line 42</span>

<span class='kw'>def</span> <span class='id identifier rubyid_default_view_model_class_for'>default_view_model_class_for</span> <span class='id identifier rubyid_model'>model</span>
  <span class='lparen'>(</span><span class='id identifier rubyid_default_prefix'>default_prefix</span> <span class='op'>+</span> <span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="specific_view_model_class_for-instance_method">
  
    - (<tt>Object</tt>) <strong>specific_view_model_class_for</strong>(model) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Returns a specific view_model class for the given model instance.</p>

<p>Override this method, if you want to return a specific view model class for
the given model.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt>NameError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>if a corresponding ViewModels constant cannot be loaded.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


53
54
55</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/view_models/helpers/mapping.rb', line 53</span>

<span class='kw'>def</span> <span class='id identifier rubyid_specific_view_model_class_for'>specific_view_model_class_for</span> <span class='id identifier rubyid_model'>model</span>
  <span class='id identifier rubyid_specific_view_model_mapping'>specific_view_model_mapping</span><span class='lbracket'>[</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="view_model_class_for-instance_method">
  
    - (<tt>Object</tt>) <strong>view_model_class_for</strong>(model) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
  <div class="note notetag">
    <strong>Note:</strong>
    <div class='inline'>
<p>ViewModels are usually of class ViewModels::&lt;ModelClassName&gt;. (As
returned by default_view_model_class_for). Override specific_mapping if
you'd like to install your own. Or Override
default_view_model_class_for(model) if you'd like to change the default.</p>
</div>
  </div>


<p>Get the view_model class for the given model instance.</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


28
29
30</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/view_models/helpers/mapping.rb', line 28</span>

<span class='kw'>def</span> <span class='id identifier rubyid_view_model_class_for'>view_model_class_for</span> <span class='id identifier rubyid_model'>model</span>
  <span class='id identifier rubyid_specific_view_model_class_for'>specific_view_model_class_for</span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_default_view_model_class_for'>default_view_model_class_for</span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="view_model_for-instance_method">
  
    - (<tt>Object</tt>) <strong>view_model_for</strong>(model, context = self) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
  <div class="note notetag">
    <strong>Note:</strong>
    <div class='inline'>
<p>context is either a view instance or a controller instance.</p>
</div>
  </div>


<p>Create a new view_model instance for the given model instance with the
given arguments.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt>ArgumentError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>if the view model class doesn't support 2 arguments.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


20
21
22</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/view_models/helpers/mapping.rb', line 20</span>

<span class='kw'>def</span> <span class='id identifier rubyid_view_model_for'>view_model_for</span> <span class='id identifier rubyid_model'>model</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='kw'>self</span>
  <span class='id identifier rubyid_view_model_class_for'>view_model_class_for</span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_model'>model</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    <div id="footer">
  Generated on Tue Oct 16 23:27:34 2012 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.3 (ruby-1.9.3).
</div>

  </body>
</html>